package org.smartjava.concurrent.core;

/**
 * 顺序执行还是并发执行
 */
public class E1SerialOrConcurrent {

    public static void main(String[] args) {
        int num = 10;
        serialNumber(num);
        System.out.println("----------------------");
      
    }

    private static void serialNumber(int num) {
        for (int i = 0; i < num; i++) {
            System.out.println(i);
        }
    }

    private static void printNumInThread(int num) {
        for (int i = 0; i < num; i++) {
            int x = i;
            new Thread(() -> System.out.println(x)).start();
        }
    }

    private static void printNumInRunnable(int num) {
        for (int i = 0; i < num; i++) {
            int x = i;
            Runnable runnable = () -> System.out.println(x);
            runnable.run();
        }
    }
}
